﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
   public class LiveService
    {
        //新增
       public static bool AddLive(Live lv)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Lv_GmId",lv.Lv_GmId), new SqlParameter("@Lv_Title",lv.Lv_Title),
            new SqlParameter("@Lv_Tv",lv.Lv_Tv),new SqlParameter("@Lv_GtId",lv.Lv_GtId)};
            return DBHelper.Instance().ExcuteProcedure("up_AddLive", para);
        }
        //删除
       public static bool DeleLive(int id)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Lv_Id", id) };
            return DBHelper.Instance().ExcuteProcedure("up_DeleLive", para);
        }
       //删除指定游戏id内容
       public static bool DeleGmIdLive(int id)
       {
           SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Lv_GmId", id) };
           return DBHelper.Instance().ExcuteProcedure("up_DeleGmIdLive", para);
       }
        //修改全部内容
       public static bool UpdaLive(Live lv)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Lv_GmId",lv.Lv_GmId), new SqlParameter("@Lv_Title",lv.Lv_Title),
            new SqlParameter("@Lv_Tv",lv.Lv_Tv),new SqlParameter("@Lv_GtId",lv.Lv_GtId),new SqlParameter("@Lv_Id",lv.Lv_Id)};
            return DBHelper.Instance().ExcuteProcedure("up_UpdaLive", para);
        }
        //查询所有信息
       public static List<Live> SeleAllLive()
        {
            List<Live> item = new List<Live>();
            string sql = string.Format("select * from Live ");
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Live lv = new Live();
                    lv.Lv_Id = Convert.ToInt32(dt.Rows[i]["Lv_Id"].ToString());
                    lv.Lv_GmId = Convert.ToInt32(dt.Rows[i]["Lv_GmId"].ToString());
                    lv.Lv_Title = dt.Rows[i]["Lv_Title"].ToString();
                    lv.Lv_Tv = dt.Rows[i]["Lv_Tv"].ToString();
                    lv.Lv_GtId = Convert.ToInt32(dt.Rows[i]["Lv_GtId"].ToString());
                    item.Add(lv);
                }
            }
            return item;
        }
        //查指定定id信息
       public static List<Live> SeleIdLive(int id)
       {
           List<Live> item = new List<Live>();
           string sql = string.Format("select * from Live where Lv_Id='{0}'",id);
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           if (dt != null && dt.Rows.Count > 0)
           {
               for (int i = 0; i < dt.Rows.Count; i++)
               {
                   Live lv = new Live();
                   lv.Lv_Id = Convert.ToInt32(dt.Rows[i]["Lv_Id"].ToString());
                   lv.Lv_GmId = Convert.ToInt32(dt.Rows[i]["Lv_GmId"].ToString());
                   lv.Lv_Title = dt.Rows[i]["Lv_Title"].ToString();
                   lv.Lv_Tv = dt.Rows[i]["Lv_Tv"].ToString();
                   lv.Lv_GtId = Convert.ToInt32(dt.Rows[i]["Lv_GtId"].ToString());
                   item.Add(lv);
               }
           }
           return item;
       }

       //查指定定gmid信息
       public static List<Live> SeleGmIdLive(int id)
       {
           List<Live> item = new List<Live>();
           string sql = string.Format("select top 1 * from Live where Lv_GmId='{0}'", id);
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           if (dt != null && dt.Rows.Count > 0)
           {
               for (int i = 0; i < dt.Rows.Count; i++)
               {
                   Live lv = new Live();
                   lv.Lv_Id = Convert.ToInt32(dt.Rows[i]["Lv_Id"].ToString());
                   lv.Lv_GmId = Convert.ToInt32(dt.Rows[i]["Lv_GmId"].ToString());
                   lv.Lv_Title = dt.Rows[i]["Lv_Title"].ToString();
                   lv.Lv_Tv = dt.Rows[i]["Lv_Tv"].ToString();
                   lv.Lv_GtId = Convert.ToInt32(dt.Rows[i]["Lv_GtId"].ToString());
                   item.Add(lv);
               }
           }
           return item;
       }

       //查指定游戏信息
       public static List<Live> SeleGameLive(string name)
       {
           List<Live> item = new List<Live>();
           string sql = string.Format("select * from Live where Lv_Title like '%{0}%'", name);
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           if (dt != null && dt.Rows.Count > 0)
           {
               for (int i = 0; i < dt.Rows.Count; i++)
               {
                   Live lv = new Live();
                   lv.Lv_Id = Convert.ToInt32(dt.Rows[i]["Lv_Id"].ToString());
                   lv.Lv_GmId = Convert.ToInt32(dt.Rows[i]["Lv_GmId"].ToString());
                   lv.Lv_Title = dt.Rows[i]["Lv_Title"].ToString();
                   lv.Lv_Tv = dt.Rows[i]["Lv_Tv"].ToString();
                   lv.Lv_GtId = Convert.ToInt32(dt.Rows[i]["Lv_GtId"].ToString());
                   item.Add(lv);
               }
           }
           return item;
       }

    }
}
